﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using System.Windows.Media.Media3D;


namespace N6SCRM.APP
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        //private DispatcherTimer dispatcherTimer;

        public MainWindow()
        {
         
            InitializeComponent();

            initializeUserInterfaceElements();



        }


        private bool initializeUserInterfaceElements()
        {
            bool retval = false;
            try
            {

               // animatedLogo.Height = 500;
               // animatedLogo.Width = 500;

                //dispatcherTimer = new DispatcherTimer();
                //dispatcherTimer.Interval = TimeSpan.FromSeconds(12);
                //dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
                //dispatcherTimer.IsEnabled = true;

                //Random r = new Random(DateTime.Now.Second);
                //int a = (DateTime.Now.Second > 30) ? 1 : -1;
                //DoubleAnimation tl = new DoubleAnimation(a * 360, TimeSpan.FromSeconds(8));
                //tl.RepeatBehavior = RepeatBehavior.Forever;

                //axisanglerotation.Axis = new Vector3D(r.Next(2), r.Next(2), 1);
                //axisanglerotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, tl);



                Button btn = dashboard.GeMainUserButton() as Button;
                btn.Tag = dashboard.Name;
                btn.Click += new RoutedEventHandler(MainUserButtonsContainerItem_Click);
                MainUserButtonsContainer.Children.Add(btn);

                btn = planner.GeMainUserButton() as Button;
                btn.Tag = planner.Name;
                btn.Click += new RoutedEventHandler(MainUserButtonsContainerItem_Click);
                MainUserButtonsContainer.Children.Add(btn);

                btn = compositeAccountControl.GeMainUserButton() as Button;
                btn.Tag = compositeAccountControl.Name;
                btn.Click += new RoutedEventHandler(MainUserButtonsContainerItem_Click);
                MainUserButtonsContainer.Children.Add(btn);

                btn = new Button();
                btn.Height = 20;
                btn.Width = 20;
                btn.Content = "About";
                btn.Click += new RoutedEventHandler(btnAbout_Click);
                UserUtilityButtonsContainer.Children.Add(btn);
                


                //Button tempBtn;
                //for (int i = 0; i < 9; i++)
                //{
                //    tempBtn = new Button();
                //    tempBtn.Height = 75;
                //    tempBtn.Width = 75;
                //    tempBtn.Content = i.ToString();
                //    tempBtn.Tag = i.ToString();
                //    tempBtn.Click += new RoutedEventHandler(MainUserButtonsContainerItem_Click);
                //    MainUserButtonsContainer.Children.Add(tempBtn);
                //}

                //for (int i = 20; i < 29; i++)
                //{
                    
                //    tempBtn = new Button();
                //    tempBtn.Height = 20;
                //    tempBtn.Width = 20;
                //    tempBtn.Content = i.ToString();
                //    tempBtn.Tag = i.ToString();
                //    tempBtn.Click += new RoutedEventHandler(MainUserButtonsContainerItem_Click);
                //    UserUtilityButtonsContainer.Children.Add(tempBtn);
                //}


            }
            catch (Exception eX)
            {
                retval = false;
            }
            finally
            {
            }
            return retval;
        }

        void btnAbout_Click(object sender, RoutedEventArgs e)
        {
            AboutBox ab = new AboutBox(this);
            ab.Title = "About Nexus6Studio CRM";
            ab.ShowDialog();

            //N6SCRM.APP.App.ShowAppSplash();
            //Splash s = new Splash();
            //s.Show();

        }

        void MainUserButtonsContainerItem_Click(object sender, RoutedEventArgs e)
        {

            foreach (UIElement u in UserControlContainer.Children)
            {
                u.Visibility = System.Windows.Visibility.Hidden;
            }

            UserControl uc = UserControlContainer.FindName(((Button)sender).Tag.ToString()) as UserControl;
            uc.Visibility = System.Windows.Visibility.Visible;

        }

        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            UserControlContainer.Height = RootLayoutGrid.RowDefinitions[1].ActualHeight;
            UserControlContainer.Width = RootLayoutGrid.ColumnDefinitions[0].ActualWidth;



        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
            Application.Current.Shutdown();
        }

        //private void dispatcherTimer_Tick(object sender, EventArgs e)
        //{
        //    Random r = new Random();
        //    //text1.Text = str[r.Next(str.Length)] + " ";

        //    DoubleAnimation da = new DoubleAnimation(0, TimeSpan.FromSeconds(5));
        //    da.From = 0;
        //    da.To = 1;
        //    da.AutoReverse = true;
        //    //text1.BeginAnimation(TextBlock.OpacityProperty, da);
        //}


    }
}
